<template>
  <div class="searchCon">
    <div class="sellItemBox" v-for="(item, index) in searchArr" :key="item.category_id + '' + index">
      <a class="sellBox" :href="item.coupon_click_url" target="_blank">
        <el-image class="image" :lazy="true" :src="item.pict_url" fit="fill"></el-image>
        <div class="priceBox">
          <span class="oldPrice">￥{{item.zk_final_price}}</span>
          <span class="newPrice">劵后价：{{item.coupon_start_fee}}</span>
        </div>
        <div class="peopleNum">{{item.coupon_remain_count}} · 人已购买</div>
        <div class="title">{{item.title}}</div>
      </a>
    </div>
  </div>
</template>

<script>
  export default {
    name: "index",
    async asyncData({query, $axios}){
      let {keyword} = query;

      let res = await $axios("/api/search", {
        params: {
          page: 1,
          keyword: keyword
        }
      });

      let searchArr = [];
      if (res.code === 10000){
        searchArr = res.data.tbk_dg_material_optional_response.result_list.map_data
      }
      return {
        keyword,
        searchArr,
      }
    }
  }
</script>

<style scoped lang="scss">
  .searchCon{
    display: flex;
    flex-wrap: wrap;
    margin-left: -10px;
    margin-right: -10px;
    padding: 10px 0;
    line-height: 26px;

    .sellItemBox{
      width: 25%;
      padding: 10px;
      box-sizing: border-box;

      .sellBox{
        box-shadow: 0 0 4px #aaa;
        padding: 5px;
        box-sizing: border-box;
        display: block;

        .image{
          width: 100%;
          height: 300px;
        }

        .priceBox{
          color: red;
          font-size: 14px;
          .oldPrice{
            text-decoration: line-through;
            width: 150px;
          }
        }

        .peopleNum{
          font-size: 12px;
          color: #999;
        }

        .title{
          font-size: 14px;
        }
      }
    }

  }


</style>
